package com.da.lon.wang.xlg.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.AddressList;
import com.da.lon.wang.xlg.util.ViewHolder;

import java.util.List;

public class FixAddressAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<AddressList> addressLists;

    public FixAddressAdapter(List<AddressList> list, Context context) {
        // TODO Auto-generated constructor stub

        inflater = LayoutInflater.from(context);
        this.addressLists = list;

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return addressLists != null ? addressLists.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return addressLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        AddressList addressList = addressLists.get(position);

        convertView = inflater
                .inflate(R.layout.ouka_address_listviewitem, null);

        TextView nameView = ViewHolder
                .get(convertView, R.id.order_address_name);
        TextView phoneView = ViewHolder.get(convertView,
                R.id.order_address_phone);
        TextView locationView = ViewHolder.get(convertView,
                R.id.order_address_location);
        TextView textView = ViewHolder
                .get(convertView, R.id.order_address_text);
        ImageView selectView = ViewHolder.get(convertView,
                R.id.order_address_select);

        if (position == 0) {
            LinearLayout firstLayout = ViewHolder.get(convertView,
                    R.id.order_address);
            firstLayout.setBackgroundColor(Color.parseColor("#5D6B85"));

            nameView.setTextColor(Color.parseColor("#ffffff"));
            phoneView.setTextColor(Color.parseColor("#ffffff"));
            locationView.setTextColor(Color.parseColor("#ffffff"));
            textView.setTextColor(Color.parseColor("#ffffff"));
            selectView.setVisibility(View.VISIBLE);
        }

        nameView.setText(addressList.getReal_name());
        phoneView.setText(addressList.getTelphone());
        if (addressList.getCounty_name() == null) {
            locationView.setText(addressList.getPro_name()
                    + addressList.getCity_name() + addressList.getAddress());
        } else {
            locationView.setText(addressList.getPro_name()
                    + addressList.getCity_name() + addressList.getCounty_name()
                    + addressList.getAddress());
        }

        return convertView;
    }

}
